package controller

import (
	"appService/src/application"
	"appService/src/application/app/authGroup"
	"appService/src/libs/crypot"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)
//AuthGroup 菜单权限组
type AuthGroup struct {
	application.BaseController
}

//GetAppCode 获取加密之后的 权限标识【AppCode】
func (this *AuthGroup) GetAppCode(r *ghttp.Request) {
	req:=this.NewRequest(r,nil)
	id := r.GetString("id")
	if id == "" {
		req.JsonError("请选择要获取【权限标识】的【权限组】")
	}
	ag,has:= authGroup.Get(id)
	if !has{
		req.JsonError("权限组不存在")
	}
	appCode , err := crypot.AESEncrypt(ag.Id)
	if err !=nil {
		g.Log().Errorf("【GetAppCode】 —> AESEncrypt：加密错误：%v", err)
		req.JsonError("获取失败")
	}
	req.JsonSuccessData(appCode)
}
//ShareId 获取共享端ID
func (this *AuthGroup) ShareId(r *ghttp.Request){
	req:=this.NewRequest(r,nil)
	req.JsonSuccessData(authGroup.SHARE_ID)
}
//List 获取权限组列表
func (this *AuthGroup) List(r *ghttp.Request){
	req:=this.NewRequest(r,nil)
	req.JsonSuccessData(authGroup.List())
}